package com.gxa.p2p.controller;

import com.alibaba.excel.EasyExcel;
import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.*;
import com.gxa.p2p.service.*;
import com.gxa.p2p.service.impl.ActivityServiceImpl;
import com.gxa.p2p.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-25 19:58
 */
@CrossOrigin
@RestController
@RequestMapping("/export")

//@Transactional
@Api(value = "导出操作接口")
public class ExportController {

    @Autowired
    MarkService markService;

    @Autowired
    RepaymentService repaymentService;

    /**
     * 接口18.1
     * 廖泓宇
     */
    @RequestMapping(value = "/investMarkByCondition",method = RequestMethod.GET)
    @ApiOperation("投资标导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "借款方电话",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "标名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "from",value = "起始时间",required = false,dataType = "TimeStamp"),
            @ApiImplicitParam(name = "to",value = "终止时间",required = false,dataType = "TimeStamp"),
            @ApiImplicitParam(name = "state1",value = "状态1",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state2",value = "状态2",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state3",value = "状态3",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state4",value = "状态4",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state5",value = "状态5",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state6",value = "状态6",required = false,dataType = "String")

    })
    public void investMarkByCondition(
//                                                         @RequestParam("phone")
                                                                     String phone,
//                                                         @RequestParam("name")
                                                                    String name,
//                                                         @RequestParam("from")
                                                                     String from,
//                                                         @RequestParam("to")
                                                                     String to,
//                                                         @RequestParam("page")
                                                                     Integer page,
//                                                         @RequestParam("size")
                                                                     Integer size,
//                                                         @RequestParam("state1")
                                                                     String state1,
//                                                         @RequestParam("state2")
                                                                     String state2,
//                                                         @RequestParam("state3")
                                                                     String state3,
//                                                         @RequestParam("state4")
                                                                     String state4,
//                                                         @RequestParam("state5")
                                                                     String state5,
//                                                         @RequestParam("state6")
                                                                     String state6,
                                                                     HttpServletResponse response,
                                                                     HttpServletRequest request) throws IOException {
        Timestamp from1 = null;  Timestamp to1 = null;
        if(!StringUtil.isEmpty(from) ){
            from1 = Timestamp.valueOf(from);
        }
        if(!StringUtil.isEmpty(to) ){
            to1 = Timestamp.valueOf(to);
        }
        //要导出的数据
        List<Investrecord> allLikeByPageTZ = markService.findAllLikeByPageTZExport(phone,name, from1, to1, state1, state2, state3, state4, state5, state6);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("投资记录表");
        String fileName = "投资记录表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"标的编号", "投资人", "借款人手机", "标名", "投资金额", "利息", "利息管理费", "收益方式", "已收金额", "待收总额", "投资渠道"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 添加数据行:
        int rowNum = 1;
        for (Investrecord item : allLikeByPageTZ) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            if (item.getMid() == null) {
                dataRow.createCell(0).setCellValue("");
            } else {
                dataRow.createCell(0).setCellValue(item.getMid());
            }

            if (item.getUserName() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getUserName());
            }

            if (item.getPhone() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getPhone());
            }

            if (item.getMarkName() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getMarkName());
            }

            if (item.getInvestMoney() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getInvestMoney());
            }

            if (item.getRate() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getRate());
            }

            if (item.getManageExpense() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getManageExpense());
            }

            if (item.getIncomeMode() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getIncomeMode());
            }

            if (item.getReceived() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getReceived());
            }

            if (item.getNoRecivedMoney() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getNoRecivedMoney());
            }

            if (item.getChannel() == null) {
                dataRow.createCell(10).setCellValue("");
            } else {
                dataRow.createCell(10).setCellValue(item.getChannel());
            }
            rowNum++;
        }
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    /**
     * 接口22.1
     * 廖泓宇
     */
    @RequestMapping(value = "/repayByCondition",method = RequestMethod.GET)
    @ApiOperation("还款管理全查（可条件模糊）导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "borrowName", value = "借款方名字", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "借款方手机号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "state1", value = "状态1", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state2", value = "状态2", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state3", value = "状态3", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state4", value = "状态4", required = false, dataType = "Integer")

    })
    public void repayByCondition( String borrowName,
                                                    String phone,
                                                    String state1,
                                                    String state2,
                                                    String state3,
                                                    String state4,
                                  HttpServletResponse response,
                                  HttpServletRequest request) throws IOException {

        //要导出的数据
        List<Repayrecord> repay = repaymentService.findRepayCountExport(borrowName, phone, state1, state2, state3, state4);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("还款表");
        String fileName = "还款表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"编号", "借款方", "借款人手机", "标名", "借款金额", "期限", "还款方式", "期数", "应还款时间", "实际还款时间", "预留金额", "实还金额", "本金","利息","逾期罚息"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 添加数据行:
        int rowNum = 1;
        for (Repayrecord item : repay) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            dataRow.createCell(0).setCellValue(item.getId());
            if (item.getId() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getId());
            }

            if (item.getBorrowName() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getBorrowName());
            }

            if (item.getBorrowPhone() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getBorrowPhone());
            }

            if (item.getMarkName() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getMarkName());
            }

            if (item.getBorrowMoney() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getBorrowMoney());
            }

            if (item.getTerm() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getTerm());
            }

            if (item.getRepayMode() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getRepayMode());
            }

            if (item.getPeriods() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getPeriods());
            }

            if (item.getRepayTime1() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getRepayTime1());
            }

            if (item.getRepayTime2() == null) {
                dataRow.createCell(10).setCellValue("");
            } else {
                dataRow.createCell(10).setCellValue(item.getRepayTime2());
            }

            if (item.getRepayMoney1() == null) {
                dataRow.createCell(11).setCellValue("");
            } else {
                dataRow.createCell(11).setCellValue(dateFormat.format(item.getRepayMoney1()));
            }
            if (item.getRepayMoney2() == null) {
                dataRow.createCell(12).setCellValue("");
            } else {
                dataRow.createCell(12).setCellValue(dateFormat.format(item.getRepayMoney2()));
            }
            if (item.getPrincipal()== null) {
                dataRow.createCell(13).setCellValue("");
            } else {
                dataRow.createCell(13).setCellValue(dateFormat.format(item.getPrincipal()));
            }
            if (item.getInterest() == null) {
                dataRow.createCell(14).setCellValue("");
            } else {
                dataRow.createCell(14).setCellValue(dateFormat.format(item.getInterest()));
            }
            if (item.getOverFine() == null) {
                dataRow.createCell(15).setCellValue("");
            } else {
                dataRow.createCell(15).setCellValue(dateFormat.format(item.getOverFine()));
            }
            rowNum++;
        }
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());

    }


    /**
     * 接口17.1
     * 廖泓宇
     */
    @GetMapping(value = "/loanMarkByCondition")
    @ApiOperation("所有借款标导出接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "legalName",value = "借款方名字",required = false,dataType = "Long"),
            @ApiImplicitParam(name = "phone",value = "借款方手机号",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state1",value = "状态1",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state2",value = "状态2",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state3",value = "状态3",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state4",value = "状态4",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state5",value = "状态5",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state6",value = "状态6",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state7",value = "状态7",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state8",value = "状态8",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state9",value = "状态9",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state10",value = "状态10",required = false,dataType = "String")

    })
    public void loanMarkByCondition(
//                                                @RequestParam("legalName")
                                                             String legalName,
//                                                 @RequestParam("phone")
                                                             String phone,
//                                                 @RequestParam("state1")
                                                             String state1,
//                                                 @RequestParam("state2")
                                                             String state2,
//                                                 @RequestParam("state3")
                                                             String state3,
//                                                 @RequestParam("state4")
                                                             String state4,
//                                                 @RequestParam("state5")
                                                             String state5,
//                                                 @RequestParam("state6")
                                                             String state6,
//                                                 @RequestParam("state7")
                                                             String state7,
//                                                 @RequestParam("state8")
                                                             String state8,
//                                                 @RequestParam("state9")
                                                             String state9,
//                                                 @RequestParam("state10")
                                                             String state10,
                                                             HttpServletResponse response,
                                                             HttpServletRequest request) throws IOException {
        //要导出的数据
        List<MarkBrrowUserVo> allLikeByPageAJVO = markService.findAllLikeByPageAJVO(legalName, phone, state1, state2, state3, state4, state5, state6, state7, state8, state9, state10);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("所有借款标");
        String fileName = "所有借款标表" + ".xls";
        System.out.println("标记1");
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"借款ID", "借款方", "借款人手机", "借款名称", "借款金额", "年化利率", "还款方式", "借款期限", "期限类型", "借款管理月率", "借款管理费", "上架时间", "开售时间"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 添加数据行:
        int rowNum = 1;
        for (MarkBrrowUserVo item : allLikeByPageAJVO) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            dataRow.createCell(0).setCellValue(item.getId());
            if (item.getLegalName() == null){
                dataRow.createCell(1).setCellValue("");
            }else {
                dataRow.createCell(1).setCellValue(item.getLegalName());
            }

            if (item.getPhone() == null){
                dataRow.createCell(2).setCellValue("");
            }else {
                dataRow.createCell(2).setCellValue(item.getPhone());
            }

            if (item.getName() == null){
                dataRow.createCell(3).setCellValue("");
            }else {
                dataRow.createCell(3).setCellValue(item.getName());
            }

            if (item.getMoney() == null){
                dataRow.createCell(4).setCellValue("");
            }else {
                dataRow.createCell(4).setCellValue(item.getMoney());
            }

            if (item.getRate() == null){
                dataRow.createCell(5).setCellValue("");
            }else {
                dataRow.createCell(5).setCellValue(item.getRate());
            }

            if (item.getMode() == null){
                dataRow.createCell(6).setCellValue("");
            }else {
                dataRow.createCell(6).setCellValue(item.getMode());
            }

            if (item.getLoanTerm() == null){
                dataRow.createCell(7).setCellValue("");
            }else {
                dataRow.createCell(7).setCellValue(item.getLoanTerm());
            }

            if (item.getTermType()== null){
                dataRow.createCell(8).setCellValue("");
            }else {
                dataRow.createCell(8).setCellValue(item.getTermType());
            }

            if (item.getManageRate()== null){
                dataRow.createCell(9).setCellValue("");
            }else {
                dataRow.createCell(9).setCellValue(item.getManageRate());
            }

            if (item.getManageExpense()== null){
                dataRow.createCell(10).setCellValue("");
            }else {
                dataRow.createCell(10).setCellValue(item.getManageExpense());
            }

            if (item.getShelfTime() == null) {
                dataRow.createCell(11).setCellValue("");
            } else {
                dataRow.createCell(11).setCellValue(dateFormat.format(item.getShelfTime()));
            }
            if (item.getSaleTime() == null) {
                dataRow.createCell(12).setCellValue("");
            } else {
                dataRow.createCell(12).setCellValue(dateFormat.format(item.getSaleTime()));
            }
            rowNum++;
        }

        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());


    }

    @Autowired
    ExpmarkService expmarkService = null;
    /**
     * 饶贵钢
     * @return
     */
    @GetMapping("/expMarkLog")
    @ApiOperation("导出体验金记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "投资人手机号",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "投资人名字",required = false,dataType = "String"),
            @ApiImplicitParam(name = "userOrigin",value = "用户来源",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "状态",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = false,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = false,dataType = "int")
    })
    public void expMarkLog(
//            @RequestParam("phone")
                                                         String phone,
//                                             @RequestParam("name")
                                                     String name,
//                                             @RequestParam("userOrigin")
                                                         String userOrigin,
//                                             @RequestParam("state")
                                                         String state,
//                                             @RequestParam("page")
                                                         Integer page,
//                                             @RequestParam("size")
                                                         Integer size,
                                             HttpServletResponse response,
                                             HttpServletRequest request) throws IOException {

        //要导出的数据
        List<Expmarklog> expMarkLogByPage = expmarkService.findExpMarkLogNoPage(phone, name, userOrigin, state, page, size);
        System.out.println(expMarkLogByPage);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("体验金记录");
        String fileName = "体验金记录"+".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName,"utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = { "序号", "投资人名字", "投资人手机","用户来源","领取时间","过期时间","使用时间","投资标名","体验金额","年化收益利率","收益","状态"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for(int i=0;i<headers.length;i++){
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }

        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        // 添加数据行:
        int rowNum = 1;
        for (Expmarklog item : expMarkLogByPage) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            dataRow.createCell(0).setCellValue(item.getId());
            dataRow.createCell(1).setCellValue(item.getName());
            dataRow.createCell(2).setCellValue(item.getPhone());
            dataRow.createCell(3).setCellValue(item.getUserOrign());
            dataRow.createCell(4).setCellValue(dateFormat.format(item.getColTime()));
            dataRow.createCell(5).setCellValue(dateFormat.format(item.getOverTime()));
            if (item.getUseTime() == null){
                dataRow.createCell(6).setCellValue("-");
            }else {
                dataRow.createCell(6).setCellValue(dateFormat.format(item.getUseTime()));
            }
            dataRow.createCell(7).setCellValue(item.getMarkName());
            dataRow.createCell(8).setCellValue(item.getMoney());
            dataRow.createCell(9).setCellValue(item.getAnnual());
            dataRow.createCell(10).setCellValue(item.getIncome());
            dataRow.createCell(11).setCellValue(item.getState());
            rowNum++;
        }

        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    @Autowired
    RedPacService redPacService = null;
    /**
     * 饶贵钢
     * @return
     */
    @GetMapping("/redPacLog")
    @ApiOperation("红包记录导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "invPhone",value = "投资人手机",required = false,dataType = "String"),
            @ApiImplicitParam(name = "invName",value = "投资人名字",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "红包名称",required = false,dataType = "String"),
            @ApiImplicitParam(name = "userOrigin",value = "用户来源",required = false,dataType = "String"),
            @ApiImplicitParam(name = "colType",value = "获取方式",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "状态",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = false,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = false,dataType = "int")
    })
    public void redPacLog(
//            @RequestParam("invPhone")
                    String invPhone,
//                         @RequestParam("invName")
                                 String invName,
//                         @RequestParam("name")
                            String name,
//                         @RequestParam("userOrigin")
                            String userOrigin,
//                         @RequestParam("colType")
                            String colType,
//                         @RequestParam("state")
                            String state,
//                         @RequestParam("page")
                            Integer page,
//                         @RequestParam("size")
                            Integer size,
                    HttpServletResponse response,
                    HttpServletRequest request) throws IOException {
        List<Redpaclog> redPacLogNoPage = redPacService.findRedPacLogNoPage(invPhone, invName, name, userOrigin, colType, state, page, size);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("红包记录");
        String fileName = "红包记录"+".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName,"utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = { "序号", "红包名字", "投资人姓名","投资人手机","用户来源","获取方式","领取时间","有效期","使用时间","投资标名","年化利率","投资金额","奖励金额","状态"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for(int i=0;i<headers.length;i++){
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }

        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        // 添加数据行:
        int rowNum = 1;
        for (Redpaclog item : redPacLogNoPage) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            dataRow.createCell(0).setCellValue(item.getId());
            dataRow.createCell(1).setCellValue(item.getName());
            dataRow.createCell(2).setCellValue(item.getInvName());
            dataRow.createCell(3).setCellValue(item.getUserOrign());
            dataRow.createCell(4).setCellValue(item.getUserOrign());
            dataRow.createCell(5).setCellValue(item.getColType());
            dataRow.createCell(6).setCellValue(dateFormat.format(item.getColTime()));
            dataRow.createCell(7).setCellValue(dateFormat.format(item.getExpTime()));
            if (item.getUseTime() == null){
                dataRow.createCell(8).setCellValue("-");
            }else {
                dataRow.createCell(8).setCellValue(dateFormat.format(item.getUseTime()));
            }

            if (item.getMarkName() == null){
                dataRow.createCell(9).setCellValue("-");
            }else {
                dataRow.createCell(9).setCellValue(item.getMarkName());
            }

            if (item.getAnnual() == null){
                dataRow.createCell(10).setCellValue("-");
            }else {
                dataRow.createCell(10).setCellValue(item.getAnnual());
            }

            if (item.getMoney() == null){
                dataRow.createCell(11).setCellValue("-");
            }else {
                dataRow.createCell(11).setCellValue(item.getMoney());
            }
            dataRow.createCell(12).setCellValue(item.getIncome());
            dataRow.createCell(13).setCellValue(item.getState());
            rowNum++;
        }

        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }
/*
    *//**
     * 徐海鱼
     * *//*
    @PostMapping("/platMoney")
    @ApiOperation("导出平台资金")
    public Map exportPlatformMoney(){
        return null;
    }

    *//**
     * 徐海鱼
     * *//*
    @PostMapping("/moneyLog")
    @ApiOperation("导出资金日志")
    public Map exportMoneyLog(){
        return null;
    }

    *//**
     * 徐海鱼
     * *//*
    @PostMapping("/userMoney")
    @ApiOperation("导出用户资金")
    public Map exportUserMoney(){
        return null;
    }

    *//**
     * 徐海鱼
     * *//*
    @PostMapping(value = "/export/withdrawlog")
    @ApiOperation("导出提现记录")
    public Map exportRecord(){
        return null;
    }*/

    @Autowired
    ActivityService activityService = null;

    @GetMapping("/exportActivityLog")
    @ApiOperation("导出活动发放记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "推荐人手机",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "被邀请人姓名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "event",value = "奖励事件",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "发送状态",required = false,dataType = "Boolean"),
            @ApiImplicitParam(name = "from",value = "起止时间",required = false,dataType = "String"),
            @ApiImplicitParam(name = "to",value = "截止时间",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = false,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = false,dataType = "int")
    })
    public void findActivityLogByPage(String phone,
                                     String name,
                                     String event,
                                     Boolean state,
                                     String from,
                                     String to,
                                     Integer page,
                                     Integer size,
                                     HttpServletResponse response) throws IOException {
        List<Activitylog> activityLogList = activityService.findActivityLogByPage(phone, name, event, state, from, to, page, size);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("活动发放记录");
        String fileName = "活动发放记录"+".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName,"utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = { "序号", "邀请人手机", "被邀请人手机","被邀请人姓名","奖励事件","奖励","基数","比例","被奖励人","发放时间","状态"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for(int i=0;i<headers.length;i++){
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }

        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        // 添加数据行:
        int rowNum = 1;
        for (Activitylog item : activityLogList) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            dataRow.createCell(0).setCellValue(item.getId());
            dataRow.createCell(1).setCellValue(item.getInvPhone());
            dataRow.createCell(2).setCellValue(item.getInvedPhone());
            dataRow.createCell(3).setCellValue(item.getInvedName());
            dataRow.createCell(4).setCellValue(item.getEvent());
            dataRow.createCell(5).setCellValue(item.getReward());
            if (item.getBaseMoney() == null){
                dataRow.createCell(6).setCellValue("-");
            }else {
                dataRow.createCell(6).setCellValue(dateFormat.format(item.getBaseMoney()));
            }

            if (item.getRatio() == null){
                dataRow.createCell(7).setCellValue("-");
            }else {
                dataRow.createCell(7).setCellValue(item.getRatio());
            }

            dataRow.createCell(8).setCellValue(item.getRewardPeo());
            dataRow.createCell(9).setCellValue(dateFormat.format(item.getProTime()));
            dataRow.createCell(10).setCellValue(item.getState());
            rowNum++;
        }

        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }
}
